<?php
if(!defined('DEDEINC'))
{
	exit("Request Error!");
}

function plus_asktype(&$atts,&$refObj,&$fields)
{
	global $dsql,$_vars,$envs;
	$attlist="row=24,titlelen=24,typeid=";
	
	FillAtts($atts,$attlist);
	FillFields($atts,$fields,$refObj);
	extract($atts, EXTR_OVERWRITE);
	$wheresql = ' 1 ';
	
	if(!empty($typeid) && $typeid != 'tid')
	{
		$wheresql .= "AND reid ={$typeid}";
	}else if($typeid == 'tid'){
		$wheresql .='AND reid=0';
	}
	$query = "select id, name, asknum, tagid, reid from `#@__asktype` where $wheresql order by disorder desc, id asc";
	$dsql->Execute('me',$query);
	$tidsa = $tid2sa = $asktypes = array();
	while($asktype = $dsql->getarray())
	{
		if($asktype['reid'] == 0)
		{
			$tidsa[] = $asktype;
		}else
		{
			$tid2sa[] = $asktype;
		}

	}
	if(!empty($typeid) && $typeid != 'tid'){
		return $tid2sa;
	}
	foreach($tidsa as $tida)
	{
		$asktypes[$tida[id]] = $tida;
		foreach($tid2sa as $key => $tid2a)
		{
			if($tid2a['reid'] == $tida['id'])
			{
				$asktypes[$tid2a['id']] = $tid2a;
				unset($tid2sa[$key]);
			}
		}
	}	
	
	$revalue = array();
	$revalue = &$asktypes;
	return $revalue;
}
?>